package com.isunland.managesystem.ui;

import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseFragment;
import com.isunland.managesystem.entity.OrderSaleCollectOriginal.OrderSaleCollectContent;

public class DetailOrderColletFragment extends BaseFragment {
  protected static final String EXTRA_VLAUE =
      "com.isunland.managesystem.ui.DetailOrderColletFragment.EXTRA_VLAUE";
  //判断是出库还是入库
  protected static final String EXTRA_TYPE =
      "com.isunland.managesystem.ui.DetailOrderColletFragment.EXTRA_TYPE";

  private OrderSaleCollectContent mContent;
  private String type = "";

  public static DetailOrderColletFragment newInstence(OrderSaleCollectContent content,
      String type) {
    Bundle bundle = new Bundle();
    bundle.putSerializable(EXTRA_VLAUE, content);
    bundle.putSerializable(EXTRA_TYPE, type);
    DetailOrderColletFragment mfragment = new DetailOrderColletFragment();
    mfragment.setArguments(bundle);
    return mfragment;
  }

  @Override public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitleCustom("出入库单详情");
    //接收值
    mContent = (OrderSaleCollectContent) getArguments().getSerializable(EXTRA_VLAUE);
    type = (String) getArguments().getSerializable(EXTRA_TYPE);
  }

  @Override public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:

        if (NavUtils.getParentActivityName(getActivity()) != null) {
          NavUtils.navigateUpFromSameTask(getActivity());
        }

        break;

      default:
        break;
    }
    return super.onOptionsItemSelected(item);
  }

  @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_detail_order_collect, container, false);
    initData(v);
    return v;
  }

  private void initData(View v) {
    TextView tvDate = (TextView) v.findViewById(R.id.tv_date);
    TextView tvSalesman = (TextView) v.findViewById(R.id.tv_salesman);
    TextView tvSupplierUnit = (TextView) v.findViewById(R.id.tv_supplier_unit);
    TextView tvMaterielName = (TextView) v.findViewById(R.id.tv_materiel_name);
    TextView tvModelType = (TextView) v.findViewById(R.id.tv_modelType);
    TextView tvUnit = (TextView) v.findViewById(R.id.tv_unit);
    TextView tvListNo = (TextView) v.findViewById(R.id.tv_list_no);
    TextView tvApplyNumber = (TextView) v.findViewById(R.id.tv_apply_number);
    TextView tvRealNumber = (TextView) v.findViewById(R.id.tv_real_number);
    TextView tvListNoName = (TextView) v.findViewById(R.id.tv_list_no_name);
    TextView tvStorageName = (TextView) v.findViewById(R.id.tv_storageName);
    TextView tvApplyName = (TextView) v.findViewById(R.id.tv_apply_name);
    TextView tvRealName = (TextView) v.findViewById(R.id.tv_real_name);
    TextView tvSupplierUnitTitle = (TextView) v.findViewById(R.id.tv_customer);
    //初始化
    //选择入库
    if ("02".equals(type)) {
      //			tvListName.setText(R.string.in_list);
      tvListNoName.setText(R.string.in_list_no);
      tvApplyName.setText(R.string.apply_inNumber);
      tvRealName.setText(R.string.real_inNumber);
      tvSupplierUnitTitle.setText(R.string.supplier_unit_colon);// 供应商/单位
    }
    //选择出库
    else if ("01".equals(type)) {
      //			tvListName.setText(R.string.out_list);
      tvListNoName.setText(R.string.out_list_no);
      tvApplyName.setText(R.string.apply_outNumber);
      tvRealName.setText(R.string.real_outNumber);
      tvSupplierUnitTitle.setText(R.string.customer_unit_colon);// 客户/单位
    }

    tvDate.setText(mContent.getAppDate());
    tvSalesman.setText(mContent.getAppManName());
    tvSupplierUnit.setText(mContent.getCustomerName());
    tvMaterielName.setText(mContent.getMaterialName());
    tvModelType.setText(mContent.getMtype());
    tvUnit.setText(mContent.getMunit());
    tvListNo.setText(mContent.getInoroutBillno());
    tvStorageName.setText(mContent.getStorageName());
    tvApplyNumber.setText(mContent.getInoroutNumber());//申请出库数量
    tvRealNumber.setText(mContent.getActualInoroutNumber());//实际出库数量
  }
}
